
<template>
        <el-select @change="changeChannel" clearable :value="value" placeholder="请选择">
                <el-option v-for="item in channelOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
                <!-- <el-option label="java" :value="102"></el-option> -->
        </el-select>
</template>

<script>
  //我的测试组件 用来测试插槽slot
export default {
    name:"my-channel",
    props:['value'],
    data(){
        return{
            channelId:null,
            channelOptions:[]
        }
    },
     created(){
      this.getChannelOptions()
     },
    methods:{
        // 选择频道
         changeChannel (val) {
        // 如果清空，val是“”字符串，应该设置成 null
            if (val === '') val = null
            //将改变的数据传递给父组件
            this.$emit('input',val)
        },
         // 获取频道数据
        async getChannelOptions(){
            const res=await this.$http.get('channels')
            this.channelOptions=res.data.data.channels
        // console.log(res)
        },
    }
}
</script>

<style scoped lang="less">

</style>